/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package handler;

import model.Vare;
import database.DatabaseHandler;
import model.Varegruppe1;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
/**
 *
 * @author Mikkel
 */
public class LagerHandler {
    private ArrayList <Vare> varegruppeList;
    
    public LagerHandler(){
        varegruppeList = new ArrayList<>();
    }
    
    public Vare getAlleVarerFraLager()throws SQLException{
        Vare vare = null;
        ResultSet rs = DatabaseHandler.getInstance().select("CALL`HentAlleVarerFraLager`");
        if(rs.next()){
            vare = new Vare(rs.getInt("Varenummer"), rs.getString("Varenavn"), rs.getDouble("Indkøbspris"), rs.getDouble("UdsalgsprisDK"), rs.getDouble("UdsalgsprisEURO"), rs.getDouble("rabat"), new Varegruppe1(rs.getInt("ID"), rs.getString("Navn")));
    }
    return vare;
}
    
    public ArrayList<Vare> getVareFraLagerVedVaregruppe (String gruppeNavn) throws SQLException{
        
        ResultSet rs = DatabaseHandler.getInstance().select("CALL `HentVarerFraLagerVedVaregruppe`");
        while(rs.next()){
            varegruppeList.add(new Vare(rs.getInt("Varenummer"), rs.getString("Varenavn"), rs.getDouble("Indkøbspris"), rs.getDouble("UdsalgsprisDK"), rs.getDouble("UdsalgsprisEURO"), rs.getDouble("rabat"), new Varegruppe1(rs.getInt("ID"), rs.getString("Navn"))));
        }
        return varegruppeList;
    }
}
